﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Catering.View_Operaction;
using System.Collections;
using System.Text;
using Microsoft.Office.Core;
using System.IO;
using System.Web.Services;

namespace Catering.Catering_Page.Caipin
{
    public partial class Shipu_Week_Check : UserIsNull
    {
        public DataTable dt_Food = new DataTable();
        public DataTable DishList = new DataTable();
        public DataTable TempExamineDt = new DataTable();//用于临时存储 某日期 某餐别下的数据
        Catering.View_Operaction_Common voc = new View_Operaction_Common();
        public string[] strWeek = new string[] { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };
        public string m_ResultList = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Txt_Date.Attributes.Add("onfocus", "WdatePicker({dateFmt:'yyyy-MM'})");
                Txt_Date.Text = DateTime.Now.ToString("yyyy-MM");
                if (Session["User"] != null)
                {
                    string userid = Session["PersonnelID"].ToString();
                    int companyid = 0;
                    int groupid = 0;
                    int classid = 0;
                    bool isAdmin = false;
                    Bind_Data_to_Controls.GetCompanyByCurrentUser(userid, out companyid, out groupid, out classid, out isAdmin);
                    if (isAdmin)
                    {
                        voc.DropDownListDataBind_Group(Dr_Operaction, companyid);
                        voc.DropDownListDataBind_Class(Dr_Class, Dr_Operaction.Items[0].Value);
                    }
                    else
                    {
                        Bind_Data_to_Controls.Bind_Area_ddl(Dr_Operaction, isAdmin, groupid, companyid);
                        Bind_Data_to_Controls.Bind_Class_ddl(Dr_Operaction.SelectedItem, Dr_Class, isAdmin, classid);
                    }
                }
                DateTime dtime = GetDateTime();
                if (dtime != null && dtime > DateTime.MinValue)
                {
                    this.LoadZouDrop(dtime.Year, dtime.Month);
                    this.dr_select_Week.SelectedIndex = 0;
                    this.LoadDayDrop();
                }
                but_Seach_Click(null, null);
            }
        }

        //计算周期
        public void LoadZouDrop(int y, int M)
        {
            this.dr_select_Week.Items.Clear();
            //每月天数数组
            int[] daysMonth = new int[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
            daysMonth[1] = (0 == y % 4 && (y % 100 != 0 || y % 400 == 0)) ? 29 : 28;

            //总天数
            int daycount = daysMonth[M - 1];

            //得到1号对应的星期
            string strDatetime = y.ToString() + "-" + M.ToString() + "-01";
            int w = this.GetWeekInt(Convert.ToDateTime(strDatetime).DayOfWeek);

            int bctianshu = 0;//要想填充一个完整的table  需要补充的天数

            if (w == 1)
            {//判断1号是否是星期一
                if ((daycount % 7) == 0)
                {//判断是否能被星期整除
                    int zhouCount = daycount / 7;
                    for (int i = 1; i <= zhouCount; i++)
                    {
                        ListItem item = new ListItem();
                        item.Text = "第" + i.ToString() + "周";
                        item.Value = y.ToString() + "-" + M.ToString() + "-" + (((i - 1) * 7) + 1).ToString() + "|" + y.ToString() + "-" + M.ToString() + "-" + (i * 7).ToString();
                        this.dr_select_Week.Items.Add(item);
                    }
                }
                else
                {
                    int zhouCount = daycount / 7;
                    bctianshu = 7 - (daycount % 7); //需要补充的天数
                    for (int i = 1; i <= zhouCount; i++)
                    {
                        ListItem item = new ListItem();
                        item.Text = "第" + i.ToString() + "周";
                        item.Value = y.ToString() + "-" + M.ToString() + "-" + (((i - 1) * 7) + 1).ToString() + "|" + y.ToString() + "-" + M.ToString() + "-" + (i * 7).ToString();
                        this.dr_select_Week.Items.Add(item);
                    }
                    ListItem ite = new ListItem();
                    ite.Text = "第" + (zhouCount + 1).ToString() + "周";
                    if (M != 12)
                    {
                        ite.Value = y.ToString() + "-" + M.ToString() + "-" + ((zhouCount * 7) + 1).ToString() + "|" + y.ToString() + "-" + (M + 1).ToString() + "-" + bctianshu.ToString();
                    }
                    else
                    {
                        ite.Value = y.ToString() + "-" + M.ToString() + "-" + ((zhouCount * 7) + 1).ToString() + "|" + (y + 1).ToString() + "-" + "01" + "-" + bctianshu.ToString();
                    }
                    this.dr_select_Week.Items.Add(ite);
                }
            }
            else
            {
                int dygxingqiyi = ((w == 0) ? 1 : (8 - w)); //距离下一个星期一还有几天
                if (((daycount - dygxingqiyi) % 7) == 0)
                {
                    int zhouCount = (daycount - dygxingqiyi) / 7;
                    for (int i = 1; i <= zhouCount; i++)
                    {
                        ListItem item = new ListItem();
                        item.Text = "第" + i.ToString() + "周";
                        item.Value = y.ToString() + "-" + M.ToString() + "-" + (((i - 1) * 7) + dygxingqiyi + 1).ToString() + "|" + y.ToString() + "-" + M.ToString() + "-" + ((i * 7) + dygxingqiyi).ToString();
                        this.dr_select_Week.Items.Add(item);
                    }
                }
                else
                {
                    bctianshu = 7 - ((daycount - dygxingqiyi) % 7); //需要补充的天数
                    int zhouCount = (daycount - dygxingqiyi) / 7;
                    for (int i = 1; i <= zhouCount; i++)
                    {
                        ListItem item = new ListItem();
                        item.Text = "第" + i.ToString() + "周";
                        item.Value = y.ToString() + "-" + M.ToString() + "-" + (((i - 1) * 7) + dygxingqiyi + 1).ToString() + "|" + y.ToString() + "-" + M.ToString() + "-" + ((i * 7) + dygxingqiyi).ToString();
                        this.dr_select_Week.Items.Add(item);
                    }
                    ListItem ite = new ListItem();
                    ite.Text = "第" + (zhouCount + 1).ToString() + "周";
                    if (M != 12)
                    {
                        ite.Value = y.ToString() + "-" + M.ToString() + "-" + ((zhouCount * 7) + dygxingqiyi + 1).ToString() + "|" + y.ToString() + "-" + (M + 1).ToString() + "-" + bctianshu.ToString();
                    }
                    else
                    {
                        ite.Value = y.ToString() + "-" + M.ToString() + "-" + ((zhouCount * 7) + dygxingqiyi + 1).ToString() + "|" + (y + 1).ToString() + "-" + "01" + "-" + bctianshu.ToString();
                    }
                    this.dr_select_Week.Items.Add(ite);

                }
            }
        }

        //加载日期下拉菜单
        public void LoadDayDrop()
        {
            if (this.dr_select_Week.SelectedItem != null)
            {
                this.drop_select_day.Items.Clear();
                ListItem itemdefault = new ListItem();
                itemdefault.Text = "全周";
                itemdefault.Value = "-1";
                this.drop_select_day.Items.Add(itemdefault);
                string strdayRange = this.dr_select_Week.SelectedItem.Value;
                DateTime starttime = Convert.ToDateTime(strdayRange.Split('|')[0]);
                DateTime endtime = Convert.ToDateTime(strdayRange.Split('|')[1]);
                while (starttime <= endtime)
                {
                    ListItem item = new ListItem();
                    item.Text = starttime.ToShortDateString();
                    item.Value = starttime.ToShortDateString();
                    this.drop_select_day.Items.Add(item);
                    starttime = starttime.AddDays(1);
                }
            }
        }

        //获取周对应的值
        public int GetWeekInt(DayOfWeek week)
        {
            switch (week)
            {
                case DayOfWeek.Monday://星期一
                    return 1;
                    break;
                case DayOfWeek.Tuesday://星期二
                    return 2;
                    break;
                case DayOfWeek.Wednesday://星期三
                    return 3;
                    break;
                case DayOfWeek.Thursday://星期四
                    return 4;
                    break;
                case DayOfWeek.Friday://星期五
                    return 5;
                    break;
                case DayOfWeek.Saturday://星期六
                    return 6;
                    break;
                case DayOfWeek.Sunday://星期日
                    return 0;
                    break;
                default:
                    return -1;
                    break;
            }
        }

        //加载对应的菜
        public void LoadDishByWeek(string strWeek, string FoodID)
        {
            DateTime time = this.GetWeekTime(strWeek);
            this.DishList = new Catering_Rules.T_RecipeInformation().GetWeekList(this.Dr_Class.SelectedValue, FoodID, time.ToShortDateString()).Tables[0];
        }

        //获取对应的菜品
        public DataTable GetDishByWeek(string strWeek, string FoodID)
        {
            DateTime time = this.GetWeekTime(strWeek);
            return new Catering_Rules.T_RecipeInformation().GetWeekList(this.Dr_Class.SelectedValue, FoodID, time.ToShortDateString()).Tables[0];
        }

        //获取菜名称
        public string GetDishName(string cid)
        {
            Catering_Model.E_Dish md = new Catering_Rules.T_Dish().GetModel(Convert.ToInt32(cid));
            return md == null ? "" : md.Name;
        }

        //获取周对应的日期
        public DateTime GetWeekTime(string strWeek)
        {
            string strTime = this.dr_select_Week.SelectedValue;
            DateTime startTime = Convert.ToDateTime(strTime.Split('|')[0]);
            DateTime endTime = Convert.ToDateTime(strTime.Split('|')[1]);
            DateTime time = DateTime.Now;
            for (DateTime dtime = startTime; dtime <= endTime; dtime = dtime.AddDays(1))
            {
                if (dtime.DayOfWeek.ToString() == strWeek)
                {
                    time = dtime;
                }
            }
            return time;
        }

        //查询
        public void but_Seach_Click(object sender, EventArgs e)
        {
            this.txt_danwei.Text = "";
            this.txt_riqi.Text = "";
            this.txt_shoukonghao.Text = "";

            string groupid = Dr_Operaction.SelectedValue;
            string classid = Dr_Class.SelectedValue;
            string riqi = Txt_Date.Text.Trim();
            DateTime starttime = DateTime.MinValue;
            if (groupid == "-10" || classid == "-10" || riqi == "") return;
            DateTime.TryParse(riqi, out starttime);

            Catering_Model.OperationArea tempgroup = new Catering_Rules.OperationArea().GetModel(Convert.ToInt32(groupid));
            Catering_Model.ClassInfo tempclass = new Catering_Rules.ClassInfo().GetModel(Convert.ToInt32(classid));
            if (tempgroup != null && tempclass != null && starttime > DateTime.MinValue)
            {
                this.txt_danwei.Text = tempclass.temp1;
                this.txt_riqi.Text = "（" + starttime.ToString("MM月") + "）";
                int companyid = 0;
                string controlled = "";
                Int32.TryParse(tempgroup.temp2, out companyid);
                if (companyid > 0)
                {
                    Catering_Model.Company com = new Catering_Rules.Company().GetModel(companyid);
                    if (com != null && !string.IsNullOrEmpty(com.Controlled)) controlled = com.Controlled;
                }
                this.txt_shoukonghao.Text = controlled;
            }

            this.dt_Food = new Catering_Rules.FoodMealType().GetList(" id<>5 and id<>6 ").Tables[0];
        }

        //加载对应班组
        protected void Dr_Operaction_SelectedIndexChanged(object sender, EventArgs e)
        {
            voc.DropDownListDataBind_Class(Dr_Class, Dr_Operaction.SelectedValue);
        }

        //加载对应的日期
        protected void dr_select_Week_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.LoadDayDrop();
        }

        //导出Excel
        protected void but_out_Excel_Click(object sender, EventArgs e)
        {
            Microsoft.Office.Interop.Excel.Application excel1 = null;
            Microsoft.Office.Interop.Excel._Worksheet ws = null;
            Microsoft.Office.Interop.Excel.Range canbie = null;
            string stick = DateTime.Now.Ticks.ToString();

            try
            {
                excel1 = new Microsoft.Office.Interop.Excel.Application();
                excel1.Application.Workbooks.Add(true);//引用Excel工作簿
                //Microsoft.Office.Interop.Excel._Worksheet ws = new Microsoft.Office.Interop.Excel.WorksheetClass();
                ws = new Microsoft.Office.Interop.Excel.WorksheetClass();
                ws = (Microsoft.Office.Interop.Excel._Worksheet)excel1.ActiveSheet;//获取当前活动工作薄
                //Microsoft.Office.Interop.Excel.Range canbie;//创建Range操作一行作为标题
                excel1.Visible = false;

                #region  表头

                string groupid = Dr_Operaction.SelectedValue;
                string classid = Dr_Class.SelectedValue;
                string riqi = Txt_Date.Text.Trim();
                DateTime starttime = DateTime.MinValue;
                if (groupid == "-10" || classid == "-10" || riqi == "") return;
                DateTime.TryParse(riqi, out starttime);

                Catering_Model.OperationArea tempgroup = new Catering_Rules.OperationArea().GetModel(Convert.ToInt32(groupid));
                Catering_Model.ClassInfo tempclass = new Catering_Rules.ClassInfo().GetModel(Convert.ToInt32(classid));

                canbie = ws.get_Range(ws.Cells[1, 1], ws.Cells[1, 7]);
                canbie.MergeCells = true;//合并单元格
                canbie.HorizontalAlignment = XlVAlign.xlVAlignCenter;//居中
                canbie.Font.Bold = 2;
                ws.Cells[1, 1] = "每周配餐食谱检查表";

                canbie = ws.get_Range(ws.Cells[2, 1], ws.Cells[2, 7]);
                canbie.MergeCells = true;//合并单元格
                ws.Cells[2, 1] = "编号:" + this.txt_danwei.Text + "　　　　（" + starttime.ToString("MM月") + "）　　　　受控号:" + this.txt_shoukonghao.Text;

                #endregion

                #region 第一行标题

                canbie = ws.get_Range(ws.Cells[3, 3], ws.Cells[3, 5]);
                canbie.MergeCells = true;//合并单元格

                ws.Cells[3, 1] = "日期";
                ws.Cells[3, 2] = "餐次";
                ws.Cells[3, 3] = "品名";
                ws.Cells[3, 6] = "检查人";
                ws.Cells[3, 7] = "备注";

                canbie = ws.get_Range(ws.Cells[3, 1], ws.Cells[3, 7]);
                canbie.HorizontalAlignment = XlVAlign.xlVAlignCenter;//居中

                #endregion

                #region 主要内容

                int canbiehangshu = 4;//餐别行数
                this.dt_Food = new Catering_Rules.FoodMealType().GetList(" id<>5 and id<>6 ").Tables[0];
                for (int i = 0; i < this.strWeek.Length; i++)
                {
                    //若选择的是某天
                    if (this.drop_select_day.SelectedValue != "-1" && this.GetWeekTime(this.strWeek[i]).ToShortDateString() != this.drop_select_day.SelectedValue) continue;

                    int lieth = 2;//第几列
                    int hangth = canbiehangshu;
                    canbie = ws.get_Range(ws.Cells[hangth, 1], ws.Cells[hangth + 6, 1]);
                    canbie.MergeCells = true;//合并单元格
                    ws.Cells[hangth, 1] = GetWeekTime(this.strWeek[i]).ToString("dd日");

                    if (dt_Food != null && dt_Food.Rows.Count > 0)
                    {
                        for (int j = 0; j < dt_Food.Rows.Count; j++)
                        {
                            if (dt_Food.Rows[j]["id"].ToString() != "1")
                            {
                                canbie = ws.get_Range(ws.Cells[hangth, lieth], ws.Cells[hangth + 1, lieth]);
                                canbie.MergeCells = true;//合并单元格
                            }
                            ws.Cells[hangth, lieth] = dt_Food.Rows[j]["FMName"].ToString();
                            lieth++;
                            string rowid = dt_Food.Rows[j]["id"].ToString() == "4" ? "2" : dt_Food.Rows[j]["id"].ToString();
                            LoadDishByWeek(strWeek[i], rowid);
                            int count = 0;
                            int zao = 0;
                            int maxnum = 6;
                            if (dt_Food.Rows[j]["id"].ToString() == "1") maxnum = 3;
                            if (DishList != null && DishList.Rows.Count > 0)
                            {
                                count = DishList.Rows.Count;
                                DataTable TempDt = this.GetExamineDt(Convert.ToInt32(this.Dr_Class.SelectedValue), int.Parse(rowid), this.GetWeekTime(this.strWeek[i]).ToShortDateString());
                                if (TempDt != null && TempDt.Rows.Count > 0)
                                {
                                    DataRow TempRow = null;
                                    if (dt_Food.Rows[j]["id"].ToString() == "1") //早餐的时候
                                    {
                                        TempRow = TempDt.Select("IsExamine=1 and youxian='1'").FirstOrDefault();
                                    }
                                    else
                                    {
                                        TempRow = TempDt.Select("IsExamine=1").FirstOrDefault();
                                    }
                                    if (TempRow != null)
                                    {
                                        ws.Cells[hangth, 6] = TempRow["ExamineUserName"].ToString();
                                    }
                                }

                                for (int n = 0; n < count; n++)
                                {
                                    if (zao == maxnum) break;
                                    if (dt_Food.Rows[j]["id"].ToString() == "1")
                                    {
                                        if (DishList.Rows[n]["youxian"].ToString() == "1")
                                        {
                                            ws.Cells[hangth, lieth] = (DishList.Rows[n]["IsExamine"].ToString() == "1" ? "√ " : "□ ") + DishList.Rows[n]["Name"].ToString().Replace('N', ' ').Trim();
                                            lieth++;
                                            zao++;
                                        }
                                    }
                                    else
                                    {
                                        if (zao == 3)
                                        {
                                            hangth++;
                                            lieth = 3;
                                        }
                                        ws.Cells[hangth, lieth] = (DishList.Rows[n]["IsExamine"].ToString() == "1" ? "√ " : "□ ") + DishList.Rows[n]["Name"].ToString().Replace('N', ' ').Trim();
                                        lieth++;
                                        zao++;
                                    }
                                }
                            }

                            if (zao < maxnum)
                            {
                                for (int n = 0; n < maxnum - zao; n++)
                                {
                                    if (3 - zao == n)
                                    {
                                        hangth++;
                                        break;
                                    }
                                }
                            }

                            hangth++;
                            lieth = 2;
                            canbiehangshu = hangth;
                        }
                    }
                    else
                    {
                        canbiehangshu++;
                    }
                }
                ws.Cells.EntireColumn.AutoFit();
                canbie = ws.get_Range(ws.Cells[3, 1], ws.Cells[canbiehangshu - 1, 7]);
                canbie.Borders.LineStyle = 1;

                #endregion

                #region 底部
                canbie = ws.get_Range(ws.Cells[canbiehangshu, 1], ws.Cells[canbiehangshu, 7]);
                canbie.MergeCells = true;//合并单元格 
                ws.Cells[canbiehangshu, 1] = "注：1.配餐形式按照合同标准执行；2.夜餐：按中餐标准执行；";
                canbiehangshu++;
                canbie = ws.get_Range(ws.Cells[canbiehangshu, 1], ws.Cells[canbiehangshu, 7]);
                canbie.MergeCells = true;//合并单元格 
                ws.Cells[canbiehangshu, 1] = "　　3.检查内容：色、香、味、形、营养搭配。";
                canbiehangshu++;
                canbie = ws.get_Range(ws.Cells[canbiehangshu, 1], ws.Cells[canbiehangshu, 7]);
                canbie.MergeCells = true;//合并单元格 
                ws.Cells[canbiehangshu, 1] = "　　合格在口画“√”；不合格在口画“×”，并把不合格处理情况填写在备注栏内。";
                canbiehangshu++;
                canbie = ws.get_Range(ws.Cells[canbiehangshu, 1], ws.Cells[canbiehangshu, 7]);
                canbie.MergeCells = true;//合并单元格 
                ws.Cells[canbiehangshu, 1] = "制作人：　　　　　　　　管事/主厨：";

                #endregion

                if (!Directory.Exists(Server.MapPath("../../xls_template"))) Directory.CreateDirectory(Server.MapPath("../../xls_template"));
                ws.SaveAs(Server.MapPath("../../xls_template") + "\\" + stick + ".xls", Microsoft.Office.Interop.Excel.XlFileFormat.xlAddIn8);

            }
            finally
            {
                if (excel1 != null)
                {
                    if (ws != null)
                    {
                        if (canbie != null)
                        {
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(canbie);
                            canbie = null;

                        }
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(ws);
                        ws = null;
                    }
                }
                excel1.Application.Workbooks.Close();
                excel1.Quit();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(excel1);
                Toolss.KillExcel(excel1);
                excel1 = null;
                GC.Collect();
            }

            #region 发送

            try
            {
                string path = Server.MapPath("../../xls_template") + "\\" + stick + ".xls";
                System.IO.FileInfo file = new System.IO.FileInfo(path);
                Response.Clear();
                Response.Charset = "GB2312";
                Response.ContentEncoding = System.Text.Encoding.UTF8;
                // 添加头信息，,弹出另存为窗口  
                Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file.Name));
                //让浏览器头显示下载信息  
                Response.AddHeader("Content-Length", file.Length.ToString());
                // 指定返回一个不能被客户端读取的流，下载  
                Response.ContentType = "application/ms-excel";
                //把文件流下载到客户端  
                Response.WriteFile(file.FullName);
                // 停止页面的执行
                Response.End();
            }
            catch { }

            #endregion

        }

        protected void Txt_Date_TextChanged(object sender, EventArgs e)
        {
            DateTime dtime = GetDateTime();
            if (dtime != null && dtime > DateTime.MinValue)
            {
                this.LoadZouDrop(dtime.Year, dtime.Month);
                this.dr_select_Week.SelectedIndex = 0;
                this.LoadDayDrop();//加载日期选择
            }
        }

        public DateTime GetDateTime()
        {
            DateTime dtime = DateTime.MinValue;
            string strDate = this.Txt_Date.Text.Trim();
            if (!string.IsNullOrEmpty(strDate)) DateTime.TryParse(strDate, out dtime);
            return dtime;
        }

        //完成全部检查
        protected void but_Examine_Click(object sender, EventArgs e)
        {
            int ClassID = Convert.ToInt32(this.Dr_Class.SelectedValue);
            int FoodID = 0;//0表示所有餐别
            string startDate = this.dr_select_Week.SelectedValue.Split('|')[0];
            string endDate = this.dr_select_Week.SelectedValue.Split('|')[1];
            if (this.drop_select_day.SelectedValue != "-1")
            {
                startDate = this.drop_select_day.SelectedValue;
                endDate = this.drop_select_day.SelectedValue;
            }
            int UserID = Convert.ToInt32(Toolss.GetCookie("LoginUserID"));
            string UserName = HttpContext.Current.Server.UrlDecode(Toolss.GetCookie("LoginUserName")); 
            new Catering_Rules.T_RecipeInformation().Examine(Convert.ToInt32(ClassID), Convert.ToInt32(FoodID), startDate, endDate, UserID, UserName);
            this.but_Seach_Click(null, null);
        }

        //单个检查
        [WebMethod]
        public static ArrayList Examine(string classID, string FoodID, string strDate)
        {
            ArrayList al = new ArrayList();
            int UserID = Convert.ToInt32(Toolss.GetCookie("LoginUserID"));
            string UserName = HttpContext.Current.Server.UrlDecode(Toolss.GetCookie("LoginUserName")); 
            new Catering_Rules.T_RecipeInformation().Examine(Convert.ToInt32(classID), Convert.ToInt32(FoodID), strDate, strDate, UserID, UserName);
            al.Add("OK");
            return al;
        }

        //获取检查数据
        public DataTable GetExamineDt(int classID, int FoodID, string strDate)
        {
            return new Catering_Rules.T_RecipeInformation().GetExamineDt(classID, FoodID, strDate);
        }

        //获取食谱表Html
        public string GetShipuHtml()
        {
            StringBuilder strShipu = new StringBuilder();   //输出的食谱Html表
            for (int i = 0; i < this.strWeek.Length; i++)   //遍历整周
            {
                if (this.drop_select_day.SelectedValue != "-1" && this.GetWeekTime(this.strWeek[i]).ToShortDateString() != this.drop_select_day.SelectedValue) //只显示符合要求的数据
                {
                    continue;
                }
                string strDate = this.GetWeekTime(this.strWeek[i]).ToString("dd日"); //该星期对应的日期
                if (this.dt_Food != null && this.dt_Food.Rows.Count > 0) //判断餐别数据列表是否为空
                {
                    for (int j = 0; j < dt_Food.Rows.Count; j++) //遍历所有餐别
                    {
                        string FoodID = dt_Food.Rows[j]["id"].ToString();       //餐别ID
                        string FoodName = dt_Food.Rows[j]["FMName"].ToString(); //餐别名称

                        if (FoodID == "1") //判断是否为早餐
                        {
                            strShipu.Append(this.GetShiPuByZao(strDate, FoodID, FoodName, this.strWeek[i]));
                        }
                        else
                        {
                            strShipu.Append(this.GetShiPuByNotZao(FoodID, FoodName, this.strWeek[i]));
                        }
                    }
                }
                else //初始没有数据的情况下
                {
                    strShipu.Append("<tr>");
                    strShipu.Append("<td>" + this.GetWeekTime(this.strWeek[i]).ToString("dd日") + "</td>");
                    for (int j = 0; j < 6; j++)
                    {
                        strShipu.Append("<td>&nbsp;</td>");
                    }
                    strShipu.Append("</tr>");
                }
            }
            return strShipu.ToString();
        }

        /// <summary>
        /// 获取早餐食谱Html
        /// </summary>
        /// <param name="strDate">对应的日期</param>
        /// <param name="FoodID">餐别ID</param>
        /// <param name="FoodName">餐别名称</param>
        /// <param name="strWeek">对应的周</param>
        /// <returns>返回对应早餐Html</returns>
        public string GetShiPuByZao(string strDate, string FoodID, string FoodName, string strWeek)
        {
            StringBuilder strShipu = new StringBuilder();   //输出的食谱Html表
            strShipu.Append("<tr>");
            strShipu.Append("<td rowspan='7'>" + strDate + "</td>");   //日期
            strShipu.Append("<td>" + FoodName + "</td>");               //餐别

            FoodID = (FoodID == "4") ? "2" : FoodID; //中餐和夜餐保持一致
            DataTable DishList = this.GetDishByWeek(strWeek, FoodID);//获取对应的菜品
            int RowIndex = 0;
            if (DishList != null && DishList.Rows.Count > 0)
            {
                //遍历所有符合要求的菜品
                foreach (DataRow row in DishList.Select("youxian='1'")) 
                {
                    //最多只显示3道菜
                    if (RowIndex == 3) break;

                    strShipu.Append("<td>" + (row["IsExamine"].ToString() == "1" ? "√" : "<span>□</span>") + row["Name"].ToString() + "</td>");
                    RowIndex += 1;
                }
            }

            //如果不够3道菜 用空的单元格补充
            while (RowIndex < 3)
            {
                strShipu.Append("<td>&nbsp;</td>");
                RowIndex += 1;
            }

            //添加检查人
            DataTable TempExamineDt = this.GetExamineDt(Convert.ToInt32(this.Dr_Class.SelectedValue), int.Parse(FoodID), this.GetWeekTime(strWeek).ToShortDateString());
            if (TempExamineDt != null && TempExamineDt.Rows.Count > 0)
            {
                DataRow TempRow = TempExamineDt.Select("IsExamine=1").FirstOrDefault();
                if (TempRow != null)
                {
                    strShipu.Append("<td>" + TempRow["ExamineUserName"].ToString() + "</td>");
                }
                else
                {
                    if (TempExamineDt.Select("youxian='1'").Count() > 0)
                    {
                        strShipu.Append("<td><input type=\"button\" value=\"检查\" onclick=\"Examine('" + this.Dr_Class.SelectedValue + "','" + FoodID + "','" + this.GetWeekTime(strWeek).ToShortDateString() + "')\" /></td>");
                    }
                    else
                    {
                        strShipu.Append("<td>&nbsp;</td>");
                    }
                }
            }
            else
            {
                strShipu.Append("<td>&nbsp;</td>");
            }

            strShipu.Append("<td>&nbsp;</td>");//备注
            strShipu.Append("</tr>");
            return strShipu.ToString();
        }

        /// <summary>
        /// 获取非早餐食谱Html
        /// </summary>
        /// <param name="strDate">对应的日期</param>
        /// <param name="FoodID">餐别ID</param>
        /// <param name="FoodName">餐别名称</param>
        /// <param name="strWeek">对应的周</param>
        /// <returns>返回对应早餐Html</returns>
        public string GetShiPuByNotZao(string FoodID, string FoodName, string strWeek)
        {
            StringBuilder strShipu = new StringBuilder();   //输出的食谱Html表
            strShipu.Append("<tr>");
            strShipu.Append("<td rowspan='2'>" + FoodName + "</td>");//餐别

            FoodID = (FoodID == "4") ? "2" : FoodID; //中餐和夜餐保持一致
            DataTable DishList = this.GetDishByWeek(strWeek, FoodID);//获取对应的菜品
            int RowIndex = 0;
            if (DishList != null && DishList.Rows.Count > 0)
            {
                //遍历所有符合要求的菜品
                for (int i = 0; i < DishList.Rows.Count; i++)
                {
                    //最多只显示3道菜
                    if (RowIndex == 3) break;
                    DataRow row = DishList.Rows[i];
                    strShipu.Append("<td>" + (row["IsExamine"].ToString() == "1" ? "√" : "<span>□</span>") + row["Name"].ToString() + "</td>");
                    RowIndex += 1;
                }
            }
            //如果不够3道菜 用空的单元格补充
            while (RowIndex < 3)
            {
                strShipu.Append("<td>&nbsp;</td>");
                RowIndex += 1;
            }

            //添加检查人
            DataTable TempExamineDt = this.GetExamineDt(Convert.ToInt32(this.Dr_Class.SelectedValue), int.Parse(FoodID), this.GetWeekTime(strWeek).ToShortDateString());
            if (TempExamineDt != null && TempExamineDt.Rows.Count > 0)
            {
                DataRow TempRow = TempExamineDt.Select("IsExamine=1").FirstOrDefault();
                if (TempRow != null)
                {
                    strShipu.Append("<td>" + TempRow["ExamineUserName"].ToString() + "</td>");
                }
                else
                {
                    strShipu.Append("<td><input type=\"button\" value=\"检查\" onclick=\"Examine('" + this.Dr_Class.SelectedValue + "','" + FoodID + "','" + this.GetWeekTime(strWeek).ToShortDateString() + "')\" /></td>");
                }
            }
            else
            {
                strShipu.Append("<td>&nbsp;</td>");
            }
            strShipu.Append("<td>&nbsp;</td>");//备注
            strShipu.Append("</tr>");

            //该餐别的第2行
            strShipu.Append("<tr>");
            if (DishList != null && DishList.Rows.Count > 0)
            {
                //从第3个开始遍历所有符合要求的菜品
                for (int i = 3; i < DishList.Rows.Count; i++)
                {
                    //最多只显示3道菜
                    if (RowIndex == 6) break;
                    DataRow row = DishList.Rows[i];
                    strShipu.Append("<td>" + (row["IsExamine"].ToString() == "1" ? "√" : "<span>□</span>") + row["Name"].ToString() + "</td>");
                    RowIndex += 1;
                }
            }
            //如果不够3道菜 用空的单元格补充
            while (RowIndex < 6)
            {
                strShipu.Append("<td>&nbsp;</td>");
                RowIndex += 1;
            }
            strShipu.Append("<td>&nbsp;</td>");//检查人
            strShipu.Append("<td>&nbsp;</td>");//备注
            strShipu.Append("</tr>");

            return strShipu.ToString();
        }
    }
}